import datetime
import time
from pdf2docx import Converter
from docx import Document
from docx2pdf import convert

filePah="E:\\Decl\\VBA程序\\分单\\sample\\"
fileName = time.strftime("%Y%m%d%H%M%S", time.localtime())
tempFile = filePah + "temp" +fileName + ".docx"
modifiedFile = filePah + "modified" +fileName + ".docx"
outFile = filePah + "out" + fileName + ".pdf"
# PDF转Word
cv = Converter(filePah+"369-94369612-test.pdf")
cv.convert(tempFile, start=0, end=None)
cv.close()

# 修改Word文档
doc = Document(tempFile)
for paragraph in doc.paragraphs:
    print( paragraph.text)
    if "369" in paragraph.text:
        paragraph.text = paragraph.text.replace("369", "billNo_prefix")
doc.save(modifiedFile)

# Word转PDF
convert(modifiedFile, outFile)